package Email.auto.checker;

import java.util.TimerTask;

public class TimerControl extends TimerTask {
	private Comunication c;
	private Account a;

	private int lastNr;
	private int nr;
	private String domain;
	private String acc;

	public TimerControl(Comunication com, Account ab) {
		this.c = com;
		this.a = ab;
		lastNr = 0;
	}

	@Override
	public void run() {
		domain = a.getDomain();
		nr = c.getUnreadedMessages(domain);
		if ((nr - lastNr) > 0) {
			acc = a.getTextEmail().getText();
			if (acc != null) {
				new Notification(acc, nr);
				lastNr = nr;
			}
		}
	}
}
